package com.wgts.wgts.mvp.presenter.imp;

import com.wgts.wgts.mvp.model.IMyExtensionFansFragmentModel;
import com.wgts.wgts.mvp.model.IMyExtensionFansOrderFragmentModel;
import com.wgts.wgts.mvp.presenter.IMyExtensionFansOrderFragmentPresenter;
import com.wgts.wgts.mvp.view.IMyExtensionFansFragmentView;
import com.wgts.wgts.mvp.view.IMyExtensionFansOrderFragmentView;
import com.wgts.wgts.netmodle.HttpResultSubscriber;
import com.wgts.wgts.netmodle.req.ShopKeepFansOrderReq;
import com.wgts.wgts.netmodle.resp.OperatingDataEntity;
import com.wgts.wgts.netmodle.resp.ShopKeepFansOrderSum;

public class MyExtensionFansOrderFragmentPresenter implements IMyExtensionFansOrderFragmentPresenter {

    private IMyExtensionFansOrderFragmentView view;

    private IMyExtensionFansOrderFragmentModel model;

    private int  index = 1;

    private String userId;

    public MyExtensionFansOrderFragmentPresenter(IMyExtensionFansOrderFragmentView view, IMyExtensionFansOrderFragmentModel model) {
        this.view = view;
        this.model = model;
    }

    @Override
    public void shopKeepFansOrderSum(String userId) {
        model.shopKeepFansOrderSum(userId, new HttpResultSubscriber<ShopKeepFansOrderSum>() {
            @Override
            public void onSuccess(ShopKeepFansOrderSum shopKeepFansOrderSum) {
                view.shopKeepFansOrderSum(shopKeepFansOrderSum);
            }

            @Override
            public void _onError(int status, String msg) {
                view.onError(status, msg);
            }
        });
    }

    @Override
    public void initShopKeepFansOrderList(String userId) {
        ShopKeepFansOrderReq req = new ShopKeepFansOrderReq();
        index = 1;
        req.pageIndex = String.valueOf(index);
        req.fansUserId = userId;
        this.userId = userId;
        model.shopKeepFansOrderList(req, new HttpResultSubscriber<OperatingDataEntity>() {
            @Override
            public void onSuccess(OperatingDataEntity operatingDataEntity) {
                if(Integer.valueOf(operatingDataEntity.pageSize) > operatingDataEntity.list.size()){
                    view.initOrderList(operatingDataEntity, true);
                }else {
                    view.initOrderList(operatingDataEntity, false);
                    index++;
                }
            }

            @Override
            public void _onError(int status, String msg) {
                view.onError(status, msg);
            }
        });
    }

    @Override
    public void moreShopKeepFansOrderList() {
        ShopKeepFansOrderReq req = new ShopKeepFansOrderReq();
        req.pageIndex = String.valueOf(index);
        req.fansUserId = userId;
        model.shopKeepFansOrderList(req, new HttpResultSubscriber<OperatingDataEntity>() {
            @Override
            public void onSuccess(OperatingDataEntity operatingDataEntity) {
                if(Integer.valueOf(operatingDataEntity.pageSize) > operatingDataEntity.list.size()){
                    view.moreOrderList(operatingDataEntity, true);
                }else {
                    view.moreOrderList(operatingDataEntity, false);
                    index++;
                }
            }

            @Override
            public void _onError(int status, String msg) {
                view.onError(status, msg);
            }
        });
    }
}
